package com.itheima.mapper;

import com.itheima.domain.Office;
import com.itheima.domain.Patient;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface PatientListMapper {

    //保存挂号信息
    @Insert("insert into patient (name,gender,did,age) values (#{name}, #{gender}, #{did}, #{age})")
    public void save(Patient patient);



    //查询所有患者的集合 一对一查询 + 模糊查询
    @Results({
            @Result(column = "name",property = "name"),
            @Result(column = "gender",property = "gender"),
            @Result(column = "id",property = "id"),
            @Result(column = "content",property = "content"),
            @Result(column = "age",property = "age"),
            @Result(
                    javaType = Office.class,
                    property = "office",
                    column = "did",
                    one = @One(select = "com.itheima.mapper.OfficeMapper.findById")
            )
    })
    @Select({"<script>",
            "select * from patient",
            "<if test = 'name != null' >",
            " where name like concat('%',#{name},'%')",
            "</if>",
            "</script>"
    })
    public List<Patient> findAll(Patient patient);


}
